//
//  DDFeekBack.m
//  dingdang
//
//  Created by lichq on 7/24/15.
//  Copyright (c) 2015 阮 沧晖. All rights reserved.
//

#import "DDFeekBack.h"
#import "DDFeekBackRecord.h"
#import "UICommonFunc.h"
#import "DDNetWorkAPIClient.h"

@interface DDFeekBack ()

@property(weak, nonatomic) IBOutlet PlaceholderTextView *textView_body;
@end

@implementation DDFeekBack

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createUI];
    
    self.textView_body.layer.cornerRadius = 10;
    self.textView_body.layer.masksToBounds = YES;
    self.textView_body.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.textView_body.layer.borderWidth = .5;
    self.textView_body.placeholderColor = [UIColor lightGrayColor];
    self.textView_body.placeholder = @"我们需要您的宝贵意见，赶紧输入吧！";
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}

- (void)createUI
{
    self.view.backgroundColor = RGB(245, 245, 245);
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBarHidden = YES;
    //自定义TAB BAR UI
    [self addNavigatorTitle:NSLocalizedString(@"意见反馈", nil) parent:self.view];
    self.barViewControl.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_Background"]];
    [self AddLeftBtnAction:nil normal:@"top_返回" selected:@"top_返回" action:^{
        //[self dismissViewControllerAnimated:YES completion:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
//    BOOL isLogin = YES; //TODO 对未登录的用户记录按钮隐藏
//    if (isLogin) {
//        [self AddRightBtnAction:@"记录" normal:@"" selected:@"" action:^{
//            DDFeekBackRecord *vc = [[DDFeekBackRecord alloc]initWithNibName:@"DDFeekBackRecord" bundle:nil];
//            [self.navigationController pushViewController:vc animated:YES];
//        }];
//    }
}

- (IBAction)submit:(id)sender{
    if ([self.textView_body.text length] == 0) {
        [UICommonFunc showAlert:@"内容为空，请重新输入"];
    }else{
        NSLog(@"提交：%@", self.textView_body.text);
        DDNetWorkAPIClient *network = [[DDNetWorkAPIClient alloc] init];
        NSDictionary *dictionary = @{@"content": self.textView_body.text,
                                     @"contact": @"13055284289"
                                     };
        [network feekback:dictionary completionBlock:^(BOOL isSuccess, NSDictionary *dict, NSString *message, NSString *status) {
            if (isSuccess) {
                [UICommonFunc showAlert:@"反馈成功"];
            }else{
                [UICommonFunc showAlert:@"反馈失败"];
            }
        }];
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [self.textView_body resignFirstResponder];
    }
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    [self.textView_body resignFirstResponder];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.textView_body resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
